﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MemoLib.Tasks
{
    /// <summary>
    /// 一次性任务
    /// </summary>
    public class OnceTask :Task
    {
        public override void UpdateTaskStatus(ExcelOperator eop)
        {
            eop.UpdateCellValue(CommonData.ONCETASK_SHEETNAME, CommonData.LASTEXECUTEDATETIME, Utility.GetDateTimeString(this.Card.ExecuteDateTime), this.Card.CardID.ToString());
            string nextExecuteDateTime = Utility.GetDateTimeString(this.Card.ExecuteDateTime.AddDays(1));
            eop.UpdateCellValue(CommonData.ONCETASK_SHEETNAME, CommonData.ONCETASK_EXECUTEDATE, nextExecuteDateTime, this.Card.CardID.ToString());
        }

        public void ComplateTask()
        {
            OnceTaskCard taskCard = (OnceTaskCard)this.Card;
            taskCard.DoneDateTime = DateTime.Now;
            ExcelOperator op = new ExcelOperator(ConfigOperator.GetExcelPath());
            op.OpenConn();
            op.UpdateCellValue(CommonData.ONCETASK_SHEETNAME, CommonData.ONCETASK_DONEDATE, Utility.GetDateTimeString(DateTime.Now), this.Card.CardID.ToString());
            op.UpdateCellValue(CommonData.ONCETASK_SHEETNAME, CommonData.ONCETASK_STATUS, CommonData.ONCETASK_STATUS_COMPLETE, this.Card.CardID.ToString());
            op.CloseConn();

            // 需要将关联的todo list中的项目也设置为完成。
            TodoTask todoTask = new TodoTask();
            todoTask.UpdateTodoTask(taskCard.CardID);
        }
    }
}
